<!--
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2022-12-16 10:34:54
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2022-12-16 11:02:10
-->
<template>
  <el-select
    v-loadMore="loadMore"
    v-model="value"
    :clearable="clearable"
    :placeholder="placeholder"
    @change="change"
    @getDataList="getDataList"
  >
    <el-option
      v-for="item in dataList"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: "Pagination",
  props: {
    placeholder: {
      type: String,
      default: "请选择",
    },
    clearable: {
      type: Boolean,
      default: true,
    },
    dataList: {
      type: Array,
      default: () => [],
    },
    total: {
      //   required: true,
      type: Number,
    },
    page: {
      type: Number,
      default: 1,
    },
    // limit: {
    //   type: Number,
    //   default: 10,
    // },
  },
  data() {
    return { value: "" };
  },
  computed: {
    page1: {
      get() {
        return this.page;
      },
      set(val) {
        this.$emit("update:page", val);
      },
    },
    // pageSize: {
    //   get() {
    //     return this.limit;
    //   },
    //   set(val) {
    //     this.$emit("update:limit", val);
    //   },
    // },
  },
  methods: {
    // 下拉加载更多
    loadMore() {
      if (this.dataList.length >= this.total) return;
      this.page++;
      this.getDataList();
    },
    getDataList() {
      this.$emit("getDataList", this.page);
    },
    // 点击一项
    change(val) {
      // console.log(val);
      this.$emit("change", val);
    },
    // handleSizeChange(val) {
    //   console.log(val);
    //   if (this.currentPage * val > this.total) {
    //     this.currentPage = 1;
    //   }
    //   this.$emit("pagination", { page: this.currentPage, limit: val });
    // },
    // handleCurrentChange(val) {
    //   this.$emit("pagination", { page: val, limit: this.pageSize });
    // },
  },
};
</script>

<style scoped>
</style>
